package com.lovo.demo;

import javax.swing.JOptionPane;

public class ComSystemDemo {
	static String[][] users = {
			{"a", "a", "u", "u"}, // 保存员工等级 a为管理员 u为普通员工
			{"张三", "李四", "小兰", "小娟"}, // 保存员工姓名
			{"666", "666", "666", "666"}  // 保存员工密码  三者一一对应
	};
	
	static int index = -1; // 下标索引， 用于对应用户等级、姓名、密码
	
	public static void main(String args[]){
		process();
	}

	public static void process() {
		String userInput = JOptionPane.showInputDialog(null,"欢迎使用菜鸟驿站管理系统\n\n"
				+ "请输入选项：\n"
				+ "1. 登录系统\n"
				+ "2. 退出系统\n");
		
		if("1".equals(userInput)){
			for (int i = 0; i < 3; i++) {
				if(login()){
					menu();
				}else{
					JOptionPane.showMessageDialog(null, "用户名或密码错误");
				}
			}
			JOptionPane.showMessageDialog(null, "三次机会用完，程序退出");
		}else if("2".equals(userInput) || userInput == null){
			System.exit(0);
		}else{
			JOptionPane.showMessageDialog(null, "输入错误");
			process();
		}
	}

	public static void menu() {
		if("a".equals(users[0][index])){
			Admin.adminMenu();
		}else{
			Employee.employeeMenu();
		}
	}

	public static boolean login() {
		String username = JOptionPane.showInputDialog(null, "请输入用户名");
		String password = JOptionPane.showInputDialog(null, "请输入密码");
		
		for (int i = 0; i < users[1].length; i++) {
			if(users[1][i].equals(username)){
				index = i;
				break;
			}
		}
		
		if(index == -1 || !users[2][index].equals(password))
			return false;
		else 
			return true;
	}
	
	public static int getIndex(){
		return index;
	}
	
	public static String[][] getUsers(){
		return users;
	}
	
	public static void setUsers(String[][] newUsers){
		users = newUsers;
	}
}
